package org.glavo.bot.data

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json

object Minecraft {

    private fun readJsonProperties(resource: String): Map<String, String> =
        Data.jsonFormat.decodeFromString(Data.readResourceAsText(resource))

    @Volatile
    var lang: Map<String, String> = readJsonProperties("resources/minecraft/en_us.json")

    @Volatile
    var langZh: Map<String, String> = readJsonProperties("resources/minecraft/zh_cn.json")

    @Serializable
    data class Item(val id: Int, val displayName: String, val name: String)

    var items: List<Item> = Data.jsonFormat.decodeFromString(Data.readResourceAsText("resources/minecraft/items.json"))

    fun reload() {
        lang = readJsonProperties("resources/minecraft/en_us.json")
        langZh = readJsonProperties("resources/minecraft/zh_cn.json")
    }
}